// Table 5: Effects of road tolls and bus lanes on the driving of ICEVs 

/* =============================================================================
	STEP 1: Load driving data
============================================================================= */
use "${dataout}DrivingDataset.dta", clear

/* =============================================================================
	STEP 2: Run regressions, save results as .ster files
============================================================================= */

* First regression: Only fixed effects, time controls and selection controls
reghdfe lnkm ///
		toll_fam_mean ///
		ptl_fam_km_mean ///
		year_* month_* $selectionD ///
		/*[aw = weight]*/ ///
		if    year_2005 == 0 ///
			& year_2006 == 0 ///
			& year_2007 == 0 ///
			& year_2008 == 0 ///
			& year_2009 == 0 ///
			& year_2010 == 0 ///
			& year_2011 == 0 ///
			& year_2012 == 0 ///
			& electric == 0 ///
			& weight > 0.5 ///
			& lnkm > 0 ///
		, abs($FED) ///
		vce(cluster $FED)	
eststo reg_1
summarize lnkm if e(sample) == 1 
estadd scalar mean_lnkm 	= r(mean), replace
summarize km_dag if e(sample) == 1 
estadd scalar mean_kmdag 	= r(mean), replace
summarize toll_fam_mean if e(sample) == 1 
estadd scalar mean_toll 	= r(mean), replace
summarize ptl_fam_km_mean if e(sample) == 1 
estadd scalar mean_ptl 		= r(mean), replace
estadd local year 			= "2013-17", replace
estadd local grkFE 			= "\checkmark", replace
estadd local grkbFE 		= "\checkmark", replace
estadd local timeFE 		= "\checkmark", replace
eststo reg_1	
estimates save ${ster}table5_reg1, replace	

* Second regression: include household-level controls and commuting controls
reghdfe lnkm ///
		toll_fam_mean ///
		ptl_fam_km_mean ///
		$householdD $employmentD $ageD $distanceD $timeD $publictimeD $publicqualityD ///	
		year_* month_* $selectionD ///
		/*[aw = weight]*/ ///
		if    year_2005 == 0 ///
			& year_2006 == 0 ///
			& year_2007 == 0 ///
			& year_2008 == 0 ///
			& year_2009 == 0 ///
			& year_2010 == 0 ///
			& year_2011 == 0 ///
			& year_2012 == 0 ///
			& electric == 0 ///
			& weight > 0.5 ///
			& lnkm > 0 ///
		, abs($FED $incomeD $educationD) ///
		vce(cluster $FED)	
eststo reg_2
summarize lnkm if e(sample) == 1 
estadd scalar mean_lnkm 	= r(mean), replace
summarize km_dag if e(sample) == 1 
estadd scalar mean_kmdag 	= r(mean), replace
summarize toll_fam_mean if e(sample) == 1 
estadd scalar mean_toll 	= r(mean), replace
summarize ptl_fam_km_mean if e(sample) == 1 
estadd scalar mean_ptl 		= r(mean), replace
estadd local year 			= "2013-17", replace
estadd local grkFE 			= "\checkmark", replace
estadd local grkbFE 		= "\checkmark", replace
estadd local timeFE 		= "\checkmark", replace
estadd local indwork 		= "\checkmark", replace
estadd local hhind 			= "\checkmark", replace
eststo reg_2	
estimates save ${ster}table5_reg2, replace		

* Third regression: Control for fuel type and fuel prices as well
reghdfe lnkm ///
		toll_fam_mean ///
		ptl_fam_km_mean ///
		$householdD $employmentD $ageD $distanceD $timeD $publictimeD $publicqualityD ///	
		$carvarD ///
		year_* month_* $selectionD ///
		/*[aw = weight]*/ ///
		if    year_2005 == 0 ///
			& year_2006 == 0 ///
			& year_2007 == 0 ///
			& year_2008 == 0 ///
			& year_2009 == 0 ///
			& year_2010 == 0 ///
			& year_2011 == 0 ///
			& year_2012 == 0 ///
			& electric == 0 ///
			& weight > 0.5 ///
			& lnkm > 0 ///
		, abs($FED $incomeD $educationD) ///
		vce(cluster $FED)	
eststo reg_3
summarize lnkm if e(sample) == 1 
estadd scalar mean_lnkm = r(mean), replace
summarize km_dag if e(sample) == 1 
estadd scalar mean_kmdag = r(mean), replace
summarize toll_fam_mean if e(sample) == 1 
estadd scalar mean_toll = r(mean), replace
summarize ptl_fam_km_mean if e(sample) == 1 
estadd scalar mean_ptl 	= r(mean), replace
estadd local year 		= "2013-17", replace
estadd local grkFE 		= "\checkmark", replace
estadd local grkbFE 	= "\checkmark", replace
estadd local timeFE 	= "\checkmark", replace
estadd local indwork 	= "\checkmark", replace
estadd local hhind 		= "\checkmark", replace
estadd local car 		= "\checkmark", replace
eststo reg_3	
estimates save ${ster}table5_reg3, replace	

/* =============================================================================
	STEP 3: Create table from .ster files
============================================================================= */

eststo drop *
estimates use "${ster}table5_reg1"
eststo
estimates use "${ster}table5_reg2"
eststo
estimates use "${ster}table5_reg3"
eststo

* Write to screen
esttab ///
	, keep(toll_fam_mean ptl_fam_km_mean) ///
	coeflabels( ///
		toll_fam_mean "Road toll (NOK)" ///
		ptl_fam_km_mean "Bus lane (km)" ///
		) ///	
	stats(year N  grkFE grkbFE timeFE  indwork hhind car mean_kmdag mean_lnkm mean_toll mean_ptl , label("Year" "N" "Neighborhood residence FE" "Neighborhood work FE"  "Time and selection controls" "Commuting controls (car and PT)"  "Household and individual controls" "Fuel type and price" "Mean km/day" "Mean log(km/day)" "Mean road toll (NOK)" "Mean bus lane access (km)")) ///
se star(* 0.10 ** 0.05 *** 0.01)

* Write to latex	
esttab using "${tables}Table5.tex" ///
	, keep(toll_fam_mean ptl_fam_km_mean) ///
	coeflabels( ///
		toll_fam_mean "Road toll (NOK)" ///
		ptl_fam_km_mean "Bus lane (km)" ///
		) ///
	booktabs ///
	nonotes  nomtitle   label ///
	stats(year N  grkFE grkbFE timeFE  indwork hhind car mean_kmdag mean_lnkm mean_toll mean_ptl , label("Year" "N" "Neighborhood residence FE" "Neighborhood work FE"  "Time and selection controls" "Commuting controls (car and PT)"  "Household and individual controls" "Fuel type and price" "Mean km/day" "Mean log(km/day)" "Mean road toll (NOK)" "Mean bus lane access (km)")) ///
se star(* 0.10 ** 0.05 *** 0.01) replace



